var DB = require("../lib/db_mysql").DB;

exports.test_session = function(req,res){
  var db = new DB();
  var user_id = req.param("user_id");
  var openid = req.param("openid");
  var sql = "select * from t_user where id = ?";
  db.queryMap(sql,[user_id],function(err,result){
    req.session.user_fw = {};
    if(result){
      req.session.user_fw.openid = result.openid || openid;
    }else{
      req.session.user_fw.openid = openid;
    }
    req.session.user_fw.user = result;
    req.session.user_fw.wx = {"subscribe":1,"openid":"okFmRsw5IqC-wCpGou1-drj5i4v0","nickname":"胡纬","sex":1,"language":"zh_CN","city":"广州","province":"广东","country":"中国","headimgurl":"http://wx.qlogo.cn/mmopen/Q3auHgzwzM6WEbXCLuckNVFz92JibqxK0vF0NruVR3rrUKiaNQv5y4Do3AzicqkUL3fyeLyv0u4wO1qz2ia5JfBFhS6o5iavACnJTWvjbMydS0D0/0","subscribe_time":1473747006,"remark":"","groupid":0,"tagid_list":[]};
    return res.json(req.session.user_fw);
  })
}

exports.test_session_clear = function(req,res){
  req.session.user_fw = null;
  return res.json({success:true});
}